
require './resources/lua/states/test'

function on_quit( )
	print( "closing application" )
	sun.application:exit( )
	return true
end

function on_button( button, pressed )
	print( button .. " : " .. tostring(pressed) )
	if pressed and ( button == sun.buttons.escape ) then
		on_quit( )
	end
	return true
end

function on_focus( focused )
	sun.get_window( ):grab_cursor( focused )
	return true
end

function begin_application( )
	local window = sun.get_window( )

	window:notity_quit( on_quit )
	window:notify_button_changed( on_button )
	window:notify_focus_change( on_focus )

	settings = sun.window.window_settings( )
	settings.title = "test_sun"
	settings.width = 1280
	settings.height = 800
	settings.colour_bits = 24
	settings.depth_bits = 16
	settings.stencil_bits = 8
	settings.samples = 1
	settings.fullscreen = false
	
	-- settings.extensions:add( "GL_VERSION_3_0" )
	-- print( settings.extensions.size )
	
	-- count = 0
	-- for e in settings.extensions.values do
		-- count = count + 1
		-- print( tostring(count) .. " : " .. e )
	-- end

	if not window:create_window( settings ) then
		print( "Error creating window" )
		on_quit( )
		return
	end
	
	-- print( get_c_function()( 4 ) )
	-- print( get_functor()( 8 ) )
	-- print( get_member_function()( 12 ) )

	local state = test_state( )
	return state
end
